package com.ruoyi.dynamic.controller.app;

import com.ruoyi.common.core.annotation.valid.group.ValidGroup;
import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.context.SecurityContextHolder;
import com.ruoyi.common.core.pojo.result.Pages;
import com.ruoyi.common.core.pojo.vo.BaseVO;
import com.ruoyi.common.core.pojo.vo.MultiVO;
import com.ruoyi.common.core.pojo.vo.PageVO;
import com.ruoyi.common.core.pojo.vo.SingleVO;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.dynamic.model.pojo.entity.Gift;
import com.ruoyi.dynamic.model.pojo.entity.RoomVote;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomHeartGetRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomVoteAddRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomVoteGiveRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomVoteSearchRequest;
import com.ruoyi.dynamic.model.pojo.result.app.AppRoomVoteInfoResult;
import com.ruoyi.dynamic.service.IRoomVoteService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 房间投票 前端控制器
 * </p>
 *
 * @author Gnc
 * @since 2025-01-02
 */
@Tag(name = "App-房间礼物投票相关", description = "App-房间礼物投票相关")
@RestController
@RequestMapping(PathConstant.APP_PATH + "room-vote")
public class AppRoomVoteController {

    private final IRoomVoteService iRoomVoteService;

    public AppRoomVoteController(IRoomVoteService iRoomVoteService) {
        this.iRoomVoteService = iRoomVoteService;
    }

    @Operation(summary = "发起礼物投票", description = "发起礼物投票")
    @PostMapping
    public SingleVO<AppRoomVoteInfoResult> add(@RequestBody @Validated(ValidGroup.Insert.class) AppRoomVoteAddRequest request) {
        AppRoomVoteInfoResult result = iRoomVoteService.add(request, SecurityContextHolder.getUserId());
        return Result.single(result);
    }

    @Operation(summary = "结束投票", description = "结束投票")
    @PostMapping("over")
    public BaseVO over(@RequestBody @Validated AppRoomHeartGetRequest request) {
        boolean over = iRoomVoteService.over(request, SecurityContextHolder.getUserId());
        return Result.successOrFail(over);
    }

    @Operation(summary = "当前投票详情", description = "当前投票详情")
    @GetMapping("info")
    public SingleVO<AppRoomVoteInfoResult> info(Long id) {
        AppRoomVoteInfoResult result = iRoomVoteService.info(id);
        return Result.single(result);
    }

    @Operation(summary = "礼物投票", description = "礼物投票")
    @PostMapping("giveVote")
    public BaseVO giveVote(@RequestBody @Validated AppRoomVoteGiveRequest request) {
        boolean over = iRoomVoteService.giveVote(request, SecurityContextHolder.getUserId());
        return Result.successOrFail(over);
    }

    @Operation(summary = "本场投票记录", description = "本场投票记录")
    @GetMapping("listPage")
    public PageVO<RoomVote> listPage(@Validated AppRoomVoteSearchRequest request) {
        Pages<RoomVote> pages = iRoomVoteService.listPage(request, SecurityContextHolder.getUserId());
        return Result.page(pages);
    }

    @Operation(summary = "换一换礼物", description = "换一换礼物")
    @GetMapping("cutGift")
    public MultiVO<Gift> cutGift(Integer number) {
        return Result.multi(iRoomVoteService.cutGift(number));
    }


}
